from fastapi.middleware.cors import CORSMiddleware
from fastapi import FastAPI
from Model import Base

class APIServer():
    def __init__(self,api:FastAPI):
        self.api=api
    #region 使用跨域
    def usecores(self):
        #region 跨域设置
        self.api.add_middleware(
        CORSMiddleware,
        allow_origins=[
            "http://localhost:8000"
        ],
        allow_credentials=True,
        allow_methods=['*'],
        allow_headers=['*']
        )
        return self
    #endregion 跨域设置结束
    #region 创建模型
    def createDataBaseTable(self):
        #Base.metadata.drop_all()
        Base.metadata.create_all()
        return self
    #endregion